package com.songlanyun.modules.rights.entity;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.enums.RightsOrderConstant;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;

/**
 * 维权单，操作过程中的操作记录
 * 
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 13:45:42
 */
@Data
@TableName("yxt_sale_rights_order_operate_record")
public class RightsOrderOperateRecord extends RootEntity<Long,RightsOrderOperateRecord> implements Serializable {
	private static final long serialVersionUID = 1L;


	/**
	 * 
	 */
	@TableId
	private Long id;
	/**
	 * 维权订单标识
	 */
	@NotNull(message = "维权订单标识不能为空")
	private Long rightsOrderId;
	/**
	 * 维权订单操作状态（0申请，1同意，2买家已发货，3商家已收到退货商品,4商家发起退款支付，5已支付退款,6拒绝，7自动关闭,8主动撤消
	 */
	private RightsOrderConstant.RightsOperateStatus  rightsOperateStatus;
	/**
	 * 操作理由
	 */
	private String reason;

	/**
	 * 操作凭证图
	 */
	@JsonIgnore
	private String voucherImagesValue;

	@TableField(exist = false)
	private List<String> voucherImages;

	public void setVoucherImages(List<String> voucherImages) {
		this.voucherImages = voucherImages;
		if(voucherImages.size()==0)
		{
			this.voucherImagesValue = "";
		}
		else
		{
			this.voucherImagesValue = JSONUtil.toJsonStr(this.voucherImages );
		}

	}
	/**
	 * 把字符串映射成对象（多图）
	 */
	public void setVoucherImagesValue(String voucherImagesValue) {
		this.voucherImagesValue = voucherImagesValue;
		if (StringUtils.isEmpty(this.voucherImagesValue)) {
			setVoucherImages(new ArrayList<>());
		} else {
			try {
				setVoucherImages(ClassConvertUtils.stringToClassSnake(voucherImagesValue, new TypeReference<List< String>>() {
				}));
			} catch (IOException e) {
				throw new RRException("图片无法转List");
			}

		}
	}



	/**
	 * 操作人（0会员，1商家，2系统）
	 */
	private RightsOrderConstant.RightsOperatePerson rightsOperatePerson;
	/**
	 * 操作时间
	 */
	@TableField(fill = FieldFill.INSERT)
	private Date createTime;

	@Override
	public Long getIdentity() {
		return getId();
	}
}
